package com.xiaowen.service.impl;

import java.util.List;
import java.util.Optional;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.xiaowen.dao.ProductDao;
import com.xiaowen.entity.Product;
import com.xiaowen.service.ProductService;

@Service
public class ProductServiceImpl implements ProductService {

	@Autowired
	private ProductDao productDao;

	@Override
	public Product findById(Long id) {
		Optional<Product> optional = productDao.findById(id);
		Product product = optional.get();
		return product;
	}

	@Override
	public void save(Product product) {
		productDao.save(product);
	}

	@Override
	public void update(Product product) {
		productDao.save(product);
	}

	@Override
	public void delete(Long id) {
		productDao.deleteById(id);
	}

	@Override
	public List<Product> findAll() {
		return productDao.findAll();
	}
}
